﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Jump : MonoBehaviour
{
    private float highest = 1.9f;
    private float speed = 31;
    public GameObject obj;
    private Rigidbody rig;

    public AudioClip jumpclips;
    
    // Start is called before the first frame update
    void Start()
    {
        rig = GetComponent<Rigidbody>();
    }

    // Update is called once per frame
    void Update()
    {
        Physics.gravity = new Vector3(0, -79, 0);
        if(this.transform.position.y < highest){
            if(Input.GetKeyDown(KeyCode.Space)){
                //this.transform.Translate(Vector3.up * speed * Time.deltaTime);
                rig.velocity += Vector3.up * speed;
                AudioSource.PlayClipAtPoint(jumpclips,gameObject.transform.position);
            }
            else if(Input.GetKeyDown(KeyCode.W)){
                // this.transform.Translate(Vector3.up * speed * Time.deltaTime);
                rig.velocity += Vector3.up * speed;
                AudioSource.PlayClipAtPoint(jumpclips,gameObject.transform.position);
            }
            else if(Input.GetKeyDown(KeyCode.UpArrow)){
                // this.transform.Translate(Vector3.up * speed * Time.deltaTime);
                rig.velocity += Vector3.up * speed;
                AudioSource.PlayClipAtPoint(jumpclips,gameObject.transform.position);
            }
        }
        
        //if(Input.GetKeyDown(KeyCode.R)){
            //transform.position = new Vector3(0.4f, 1.5f, -1.23f);
        transform.forward = obj.transform.position - this.transform.position;
        //}
    }
}
